package com.xxx.gaoxi.user.controller;

import com.xxx.gaoxi.common.service.facade.entity.UserEntity;
import com.xxx.gaoxi.common.service.facade.entity.req.LoginReq;
import com.xxx.gaoxi.common.service.facade.exception.BizException;
import com.xxx.gaoxi.common.service.facade.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Description
 * ...
 * DATE 2018/4/2.
 *
 * @author Mr. Chun.
 */
@RestController
@RequestMapping("/user")
public class UserController {
    private static final Logger logger = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public UserEntity login(@RequestParam("userName") String userName, @RequestParam("password") String password) {
        LoginReq req = new LoginReq();
        req.setUserName(userName);
        req.setPassword(password);

        try {
            UserEntity entity = userService.login(req);
            return entity;
        } catch (Exception e) {
            logger.info("func: {}, e: {}", "login", e.getMessage());
            throw new BizException(e.getMessage());
        }
    }
}
